<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller{
    public function LoginAction(){
    	layout(false);
    	$username = I('post.username');
    	$password = I('post.password');
    	// var_dump($username);
    	if(IS_POST){        
    		$sql = "select * from user where username = '{$username}'"; //检验用户名密码是否存在
    		$data_m = M();
    		$res = $data_m->query($sql);
    		// var_dump($res[0]['password']);
    		// var_dump(md5($password));
    		// exit();
    		if(empty($res)){
    			$this->error("用户名或密码不正确",U('admin/login/login'),2);
    			exit();
    		}
    		if(($res[0]['password'])!=md5($password)){
    				$this->error("用户名或密码不正确",U('admin/login/login'),2);
    		}else{   			    
    			    $this->success('登录成功',U('admin/index/index'),2);
    			    $_SESSION['id'] = $res[0]['id'];
    			    $_SESSION['username'] = $username;
    		}
    		
    	}else{
    		$this->display();
    	}
    	
    }

    //验证码
    public function codeAction(){
    	$config =    array(
    	'imageW'    =>    115,    // 验证码字体大小
    	'imageH'    =>    40,    // 验证码字体大小        
    	'fontSize'    =>    20,    // 验证码字体大小    
    	'length'      =>    3,     // 验证码位数    
    	'useNoise'    =>    false, // 关闭验证码杂点
    	);
    	$Verify =     new \Think\Verify($config);
    	$Verify->entry();
    }

    //验证码检测
    function check_verify($code, $id = ''){ 
       $verify = new \Think\Verify();  
       return  $verify->check($code, $id);
   }
}

?>